import { _decorator, find, Node, Sprite } from 'cc';
import { BaseLayer } from './BaseLayer';
import { AudioMgr } from '../manager/AudioMgr';
import { ENUM_AUDIO_CLIP, ENUM_UI_LAYER } from '../Enum';
import { Ins } from '../Ins';
import { SdkMgr } from '../manager/SdkMgr';
import { EffMgr } from '../manager/EffMgr';
import { DataMgr } from '../manager/DataMgr';
import { ResMgr } from '../manager/ResMgr';
const { ccclass, property } = _decorator;

@ccclass('AnswerLayer')
export class AnswerLayer extends BaseLayer {
    btn_close: Node = null
    btn_share: Node = null
    img: Node = null

    onLoad() {
        this.img = find('panel/main/img', this.node)
        this.btn_close = find('panel/header/btn_close', this.node)
        this.btn_close.on('click', this.onCloseClick, this)
        this.btn_share = find('panel/header/btn_share', this.node)
        this.btn_share.on('click', this.onShareClick, this)
    }

    onDestroy() {
        this.btn_close.off('click', this.onCloseClick, this)
        this.btn_share.off('click', this.onShareClick, this)
    }

    onEnable() {
        SdkMgr.ins.toggleCustomRowAd(true)
        let str = `a${DataMgr.ins.level}`
        if (DataMgr.ins.isHard) str = `ah${DataMgr.ins.level}`
        this.img.getComponent(Sprite).spriteFrame = ResMgr.ins.getSprite(str)
    }

    onDisable() {
        super.onDisable()
        SdkMgr.ins.toggleCustomRowAd(false)
    }

    onCloseClick() {
        AudioMgr.ins.playSound(ENUM_AUDIO_CLIP.CLICK)
        Ins.UIMgr.toggle(ENUM_UI_LAYER.ANSWER, false)
    }

    onShareClick() {
        AudioMgr.ins.playSound(ENUM_AUDIO_CLIP.CLICK)
        if (!SdkMgr.ins.getPlatform()) {
            EffMgr.ins.showTip('EffTip', '该功能仅支持小游戏平台')
            return
        }
        SdkMgr.ins.activeShare()
    }
}


